home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / gamma_ct.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  104 lines

  1. ; $Id: gamma_ct.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1990-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro gamma_ct, gamma, CURRENT = current, INTENSITY = intensity
  8. ;+
  9. ; NAME:
  10. ;    GAMMA_CT
  11. ;
  12. ; PURPOSE:
  13. ;    Apply gamma correction to the color table.
  14. ;
  15. ; CATEGORY:
  16. ;    Image display.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    GAMMA, Gamma
  20. ;    GAMMA, Gamma, /CURRENT
  21. ;
  22. ; INPUTS:
  23. ;    Gamma:    The value of gamma correction.  A value of 1.0 indicates a
  24. ;        linear ramp, i.e., no gamma correction.  Higher values of 
  25. ;        gamma give more contrast.  Values less than 1.0 yield lower 
  26. ;        contrast.
  27. ;
  28. ; KEYWORD PARAMETERS:
  29. ;     CURRENT:    If this keyword is set, apply correction from the current 
  30. ;        table.  Otherwise, apply from the original color table.  When
  31. ;        CURRENT is set, the color table input to GAMMA_CT
  32. ;        is taken from the R_CURR, G_CURR, and B_CURR variables.
  33. ;        Otherwise, input is from R_ORIG, G_ORIG, and B_ORIG.
  34. ;        The resulting tables are always saved in the "current" table.
  35. ;
  36. ;   INTENSITY:    If this keyword is set, correct the individual intensities of 
  37. ;        each color in the color table.  Otherwise, shift the colors 
  38. ;        according to the gamma function.
  39. ;
  40. ; OUTPUTS:
  41. ;    No explicit outputs.  The modified color table vectors
  42. ;    are saved in the COLORS common block, as the variables
  43. ;    r_curr, g_curr, and b_curr variables.
  44. ;
  45. ; COMMON BLOCKS:
  46. ;    COLORS:    The IDL color table common block.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    A new color table is loaded, and its contents are placed
  50. ;    in the "current" variables of the COLORS common block.
  51. ;
  52. ; RESTRICTIONS:
  53. ;    None.
  54. ;
  55. ; PROCEDURE:
  56. ;    Straightforward.  The gamma correction is implemented
  57. ;    as x^gamma, where x is the range of color table indices
  58. ;    scaled from 0 to 1.
  59. ;
  60. ; MODIFICATION HISTORY:
  61. ;    DMS, Oct, 1990. Added ability shift intensities of colors, rather 
  62. ;            than the mapping of the colors.  DMS, April, 1991.
  63. ;-
  64. ; Copyright (c) 1990, Research Systems, Inc.  All rights reserved.
  65. ;    Unauthorized reproduction prohibited.
  66.  
  67. common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  68.  
  69. n = !d.table_size-1
  70.  
  71. if n_elements(r_orig) le 0 then begin
  72.     r_orig = indgen(n) & r_curr = r_orig
  73.     g_orig = r_orig & g_curr = g_orig
  74.     b_orig = r_orig & b_curr = b_orig
  75.     endif
  76.  
  77. if n_elements(gamma) le 0 then gamma = 1.0
  78.  
  79. if keyword_set(intensity) then begin
  80.   s = byte(256 *((findgen(256)/256.)^gamma))   ;Scale individ intensities
  81.   if keyword_set(current) then begin
  82.     r_curr = s[r_curr]
  83.     g_curr = s[g_curr]
  84.     b_curr = s[b_curr]
  85.   endif else begin
  86.     r_curr = s[r_orig]
  87.     g_curr = s[g_orig]
  88.     b_curr = s[b_orig]
  89.   endelse
  90. endif else begin   ;Scale color mapping, not intensities
  91.   s = long(n*((findgen(n)/n)^gamma))
  92.   if keyword_set(current) then begin
  93.     r_curr = r_curr[s]
  94.     g_curr = g_curr[s]
  95.     b_curr = b_curr[s]
  96.   endif else begin
  97.     r_curr = r_orig[s]
  98.     g_curr = g_orig[s]
  99.     b_curr = b_orig[s]
  100.   endelse
  101. endelse
  102. tvlct,r_curr, g_curr, b_curr
  103. end
  104.